package niumao.minecraft.uhc.listener;

import niumao.minecraft.uhc.Util;
import niumao.minecraft.uhc.recipes.UHCItem;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.Random;

public class fusionArmor implements Listener {
    @EventHandler
    public void on(CraftItemEvent event) {
        ItemStack item = event.getCurrentItem();
        assert item != null;
        ItemMeta itemMeta = item.getItemMeta();
        if (itemMeta == null) return;
        if (itemMeta.getDisplayName().equals(Util.getStr("FusionArmor"))) {
            ArrayList<ItemStack> fusion = new ArrayList<>();
            fusion.add(UHCItem.FusionHelmet());
            fusion.add(UHCItem.FusionChestPlate());
            fusion.add(UHCItem.FusionLeggings());
            fusion.add(UHCItem.FusionBoots());
            Random random = new Random();
            int choice = random.nextInt(fusion.size());
            ItemStack fusionPiece = fusion.get(choice);
            event.setCurrentItem(fusionPiece);
        }
    }
}
